package com.cloud.class05.controller;


import com.cloud.class05.entities.Storage;
import com.cloud.class05.resp.ResultData;
import com.cloud.class05.service.StorageService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StorageController {
    @Resource
    private StorageService storageService;

    /**
     * 扣减库存
     */
    @RequestMapping("/storage/decrease")
//    @PostMapping(value = "/storage/decrease")
    public ResultData decrease(Long productId, Integer count) {

        storageService.decrease(productId, count);
        return ResultData.success("扣减库存成功!");
    }

    @RequestMapping("/storage/test/{id}")
    public ResultData test(@PathVariable("id") Long id) {
        Storage storage = storageService.getStorageById(id);
        return ResultData.success(storage);
    }
}